<template>
	<view id="page" @click.stop="change_show" v-if="show">
		<!-- 安全键盘背景 -->
		<view class="key_bg">
			<!-- 安全键盘显示框,,,已设置密码 -->
			<view class="show_box BackgroundC_FFFFFF PositionR" v-if="have_pawd">
				<view @click.stop="toUrl" style="font-size: 24rpx;color:#FE481A;padding: 10rpx;position: absolute;">忘记密码?</view>
				<view class="close PositionA" @click.stop="change_show">
					<image src="./image/close.png" mode=""></image>
				</view>
				<view class="show_title dis_f_co_l_c">
					<view class="big">请输入支付密码</view>
					<view class="small">以验证您的身份</view>
				</view>
				<view class="show_text PositionR">
					<view class="number PositionA dis_f_l_c">
						<text v-for="(item,i) of number" :key="i">●</text>
					</view>
				</view>
			</view>
			<view class="show_box BackgroundC_FFFFFF PositionR" v-else-if="set_pawd">
				<view class="close PositionA" @click.stop="change_show">
					<image src="./image/close.png" mode=""></image>
				</view>
				<view class="show_title dis_f_co_l_c">
					<view class="big">{{setNum.length == 1?'请再次输入支付密码':'请设置支付密码'}}</view>
					<view class="small">以确保支付安全</view>
				</view>
				<view class="show_text PositionR">
					<view class="number PositionA dis_f_l_c">
						<text v-for="(item,i) of number" :key="i">●</text>
					</view>
				</view>
			</view>
			<!-- 安全键盘显示框,,,未设置密码 -->
			<view class="show_box BackgroundC_FFFFFF PositionR" v-else>
				<view class="close PositionA" @click.stop="change_show">
					<image src="./image/close.png" mode=""></image>
				</view>
				<view class="show_title dis_f_co_l_c">
					<view class="big">您还没有设置支付密码</view>
					<!-- <view class="small">请确保您已收到商品</view> -->
				</view>
				<view class="btn dis_f_c_c" @click.stop='to_set'>
					去设置
				</view>
			</view>
			<!-- 安全键盘输入框 -->
			<view class="enter_box" v-if="set_pawd || have_pawd">
				<view class="first dis_f_sa_c">
					<view class="item one dis_f_c_c" @click.stop="enter(1)">
						1
					</view>
					<view class="item two dis_f_c_c" @click.stop="enter(2)">
						2
					</view>
					<view class="item three dis_f_c_c" @click.stop="enter(3)">
						3
					</view>
				</view>
				<view class="second dis_f_sa_c">
					<view class="item one dis_f_c_c" @click.stop="enter(4)">
						4
					</view>
					<view class="item two dis_f_c_c" @click.stop="enter(5)">
						5
					</view>
					<view class="item three dis_f_c_c" @click.stop="enter(6)">
						6
					</view>
				</view>
				<view class="second dis_f_sa_c">
					<view class="item one dis_f_c_c" @click.stop="enter(7)">
						7
					</view>
					<view class="item two dis_f_c_c" @click.stop="enter(8)">
						8
					</view>
					<view class="item three dis_f_c_c" @click.stop="enter(9)">
						9
					</view>
				</view>
				<view class="second dis_f_r_c">
					<view class="item three dis_f_c_c" @click.stop="enter(0)">
						0
					</view>
					<view class="btn dis_f_c_c" @click.stop="delete_l">
						<image src="./image/delete.png" mode=""></image>
						<view style="font-size: 28rpx;margin-left: 10rpx;">删除</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import  from "";
	export default {
		props: {
			// 是否显示
			show: {
				type: Boolean,
				default: false,
			},
			
			//是否设置了密码
			have_pawd:{
				type: Boolean,
				default: false,
			},
			set_pawd:{
				type: Boolean,
				default: false,
			},
			setNum:{
				type: Array
			},
		},
		data() {
			return {
				// 是否刷新页面
				shua_xin: false,
				//输入的数字
				number:[]
			}
		},
		
		// 页面加载
		onLoad(e) {
			
		},
		// 页面显示
		onShow() {
			if (this.shua_xin) {

			} else {
				this.shua_xin = true;
			}
			this.number = [];
			// #ifdef H5
			// document.title = "项目模版";
			// #endif
		},
		watch:{
			number:'get_number'
		},
		// 方法
		methods: {
			toUrl(){
				uni.navigateTo({
					url:`/pages/subPagesLogin/userlogin/forgetPass?type=pay`
				})

			},
           //输入数字
		   enter(i){
			   if(this.number.length < 6){
				   this.number.push(i)
			   }
		   },
		   //监听输入的数组
		   get_number(){
			   //完成输入后发出6位密码
			   if(this.number.length ==6){
				   this.$emit('change',{
				   		number:this.number
				   })
				   if(this.set_pawd){
					   setTimeout(()=>{
						    this.number = [];
					   },300);
				   }else{
					   setTimeout(()=>{
							this.number = [];
							this.$emit("hide");
					   },300);
					   
				   }
			   }
		   },
		   //删除数字
		   delete_l(){
			   this.number.pop()
		   },
		   //页面显示隐藏
		   change_show(){
			   this.number = [];
			   this.$emit("hide",1);
		   },
		   //跳转设置密码页面
		   to_set(){
			   //console.log('跳转设置密码页面')
			   this.$emit('setPass',true)
		   }
		},
		// 页面卸载
		onUnload() {

		},
		// 触发下拉刷新
		onPullDownRefresh() {
			// 延迟关闭刷新动画
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		// 页面上拉触底事件的处理函数
		onReachBottom() {

		},
	}
</script>

<style lang="scss" scoped>
	#page {
		min-height: calc(100vh - var(--window-top));
	}
	/*相对定位*/
	.PositionR{
		position: relative;
	}
	/*绝对定位*/
	.PositionA{
		position: absolute;
	}
	.BackgroundC_FFFFFF{
		background-color: #FFFFFF;
	}
	// flex布局
	.dis_f_co_l_c{
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
	}
	.dis_f_l_c {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	.dis_f_c_c {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.dis_f_sa_c {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}
	.dis_f_r_c {
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}
    .key_bg{
		position: fixed;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 100%;
		
		background:rgba(51,51,51,0.5);
		.show_box{
			width: 590rpx;
			height: 324rpx;
			border-radius: 26rpx;
			position: fixed;
			/* #ifdef MP-WEIXIN */
			top: 286rpx;
			/* #endif */
			/* #ifndef MP-WEIXIN */
			 top: 386rpx;
			/* #endif */
			left:80rpx;
			.close{
				right: 42rpx;
				top: 40rpx;
				image{
					width: 40rpx;
					height: 40rpx;
				}
			}
			.show_title{
				width: 590rpx;
				height: 100rpx;
				margin-top: 60rpx;
				.big{
					font-weight: bold;
					font-size: 32rpx;
				}
				.small{
					font-size: 24rpx;
					color: #FE481A;
					margin-top: 10rpx;
				}
			}
			.btn{
				width: 320rpx;
				height: 64rpx;
				color: #FFFFFF;
				background:linear-gradient(270deg,rgba(253,44,7,1) 0%,rgba(255,97,43,1) 100%);
				font-size: 32rpx;
				border-radius: 10rpx;
				margin: 0 auto;
				margin-top: 50rpx;
			}
			.show_text{
				width: 554rpx;
				height: 100rpx;
				background: url(./image/text.png);
				background-size: 100% 100%;
				margin: 0 auto;
				margin-top: 38rpx;
				.number{
					width: 554rpx;
					height: 100rpx;
					top: 0;
					left: 0rpx;
					text{
						width: 92rpx;
						text-align: center;
					}
					
				}
			}
		}
		.enter_box{
			position: fixed;
			bottom: 0rpx;
			left: 0;
			width: 750rpx;
			height: 540rpx;
			background-color: #D2D5DB;
            .first{
				width: 750rpx;
				height: 92rpx;
				margin-top: 12rpx;
				.item{
					width:234rpx;
					height:92rpx;
					background:rgba(255,255,255,1);
					box-shadow:0px 2rpx 0px 0px rgba(0,0,0,0.35);
					border-radius:10rpx;
				}
				.item:active{
					background-color: #D2D5DB;
				}
			}
			.second{
				width: 750rpx;
				height: 92rpx;
				margin-top: 18rpx;
				.item{
					width:234rpx;
					height:92rpx;
					background:rgba(255,255,255,1);
					box-shadow:0px 2rpx 0px 0px rgba(0,0,0,0.35);
					border-radius:10rpx;
				}
				.item:active{
					background-color: #D2D5DB;
				}
				.btn{
					width:234rpx;
					height:92rpx;
					margin-left: 12rpx;
					margin-right: 12rpx;
					image{
						width: 48rpx;
						height: 36rpx;
					}
				}
			}
			
		}
	}
	
</style>
